<template>
<div class="peosonResultListBox main w" style="background-color:#fff;"> 
  <p class="peosonResultTitle">集体评价结果下载</p>
  <div class="resultContent">
    <el-table  
      class="el-table_inner"
      :data="tableData"
      :header-cell-style="elementStyleObj">   
      <el-table-column  
      show-header="false"          
        prop="name"
        label="按评价人员结果分类"      
        :formatter="formatter"
        header-align="center" align="center">
      </el-table-column>
      <el-table-column
        prop="tag"
        width=""
        label="下载结果"
        header-align="center" align="center">
        <template slot-scope="scope">        
          <el-button class="el-button-inner"
            size="small"
            type="danger"
            @click="handleDown(scope.$index, scope.row)" icon="el-icon-download">下载</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 参评率下载 -->
    <el-table  
      class="el-table_inner"
      :data="participationData"
      style="font-size:20px">   
      <el-table-column  
      show-header="false"  
        prop="name"        
        label=""      
        :formatter="formatter"
        header-align="center" align="center">
      </el-table-column>
      <el-table-column
        prop="tag"
        width=""
        label=""
        header-align="center" align="center">
        <template slot-scope="scoped">        
          <el-button class="el-button-inner"
            size="small"
            type="danger"
            @click="participationDown" icon="el-icon-download">下载</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 评价详情下载 -->
    <el-table  
      class="el-table_inner"
      :data="evaluatedDetail"
      style="font-size:20px">   
      <el-table-column  
      show-header="false"  
        prop="name"        
        label=""      
        :formatter="formatter"
        header-align="center" 
        align="center">
      </el-table-column>
      <el-table-column
        prop="tag"
        width=""
        label=""
        header-align="center" 
        align="center"
        >
        <template slot-scope="scoped">        
          <el-button class="el-button-inner"
            size="small"
            type="danger"
            @click="evaluatedDetailDown" icon="el-icon-download">下载</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
  
</div>
</template>
<style scoped>
/* .el-table_inner 调整表格字体 */
 .el-table_inner {
  font-family: "Microsoft" !important;
  font-size: 17px !important;
}
.el-button-inner {
  font-size: 18px;
}
.resultContent {
  font-family: "Microsoft" !important;
  width: 80%;
  margin: 50px 10% 50px;
  padding-bottom: 5%;
  -webkit-box-shadow: 0px 6px 14px #e8e8e8;
  box-shadow: 0px 6px 14px #e8e8e8;
  cursor: pointer;
}
</style>
<script>
export default {
  data() {
    return {
      tableData: [
        {
          name: "全部人员评价统计结果",
          tag: "0"
        },
        {
          name: "中层领导评价统计结果",
          tag: "1"
        },
        {
          name: "教工代表评价统计结果",
          tag: "2"
        },
        {
          name: "普通教师评价统计结果",
          tag: "3"
        }
      ],
      participationData:[
        {
          name: "参评率统计结果",
          tag: "0"
        },
      ],
      evaluatedDetail:[
        {
          name: "机关教辅各单位服务作风的意见和建议",
          tag: "0"
        },
      ],
       elementStyleObj: {
        //element 表头样式
        background: "rgb(245, 249, 255) ",
        fontSize: "20px",
        color: "#434343"
      },
    };
  },
  methods: {
    formatter(row, column) {
      return row.name;
    },
    // 按部门层级人员下载
    handleDown(index ,row){
      // console.log("123", index ,"asdas",row);
      let url = `api/department/statistics/dowland?employeeClassificationId=${index} `;
       this.$axios({
            method: "get",
            url: url,
            responseType: "blob"
          })
          .then(
            function(response) {
              let filename = row.name + '.xls';
              this.fileDownload(response.data, filename);
            }.bind(this)
          )
          .catch(
            function(error) {
              alert("网络请求出错");
            }.bind(this)
          );
    },
    //按参评率统计下载
    participationDown(){
      // console.log("657");
      let url = `api/department/statistics/downloadParticipation`;
       this.$axios({
            method: "get",
            url: url,
            responseType: "blob"
          })
          .then(
            function(response) {
              let filename = "参评率统计结果" + '.xls';
              this.fileDownload(response.data, filename);
            }.bind(this)
          )
          .catch(
            function(error) {
              alert("网络请求出错");
            }.bind(this)
          );
    },
    //机关教辅各单位服务作风的意见和建议下载
    evaluatedDetailDown(){
      // console.log("657");
      let url = `api/department/statistics/downloadEvaluatedDetail`;
       this.$axios({
            method: "get",
            url: url,
            responseType: "blob"
          })
          .then(
            function(response) {
              let filename = "机关教辅各单位服务作风的意见和建议" + '.doc';
              this.fileDownload(response.data, filename);
            }.bind(this)
          )
          .catch(
            function(error) {
              alert("网络请求出错");
            }.bind(this)
          );
    },
    fileDownload (data, fileName) {
      let blob = new Blob([data], {
        type: "application/octet-stream"
      });
      let filename = fileName || "filename.xls";
      if (typeof window.navigator.msSaveBlob !== "undefined") {
        window.navigator.msSaveBlob(blob, filename);
      } else {
        var blobURL = window.URL.createObjectURL(blob);
        var tempLink = document.createElement("a");
        tempLink.style.display = "none";
        tempLink.href = blobURL;
        tempLink.setAttribute("download", filename);
        if (typeof tempLink.download === "undefined") {
          tempLink.setAttribute("target", "_blank");
        }
        document.body.appendChild(tempLink);
        tempLink.click();
        document.body.removeChild(tempLink);
        window.URL.revokeObjectURL(blobURL);
      }
    },
  }
};
</script>